package com.swpu.cbg.cnshop.adapter;

import android.content.Context;
import android.view.View;

import com.squareup.picasso.Picasso;
import com.swpu.cbg.cnshop.R;
import com.swpu.cbg.cnshop.bean.Ware;

import java.util.List;

/**
 * Created by chenboge on 16/2/10.
 */
public class HWAdapter<T> extends BaseAdapter<T, BaseViewHolder> {


    private OnItemButtonClickListener onItemButtonClickListener;
    public HWAdapter(Context mContext, List<T> mDatas, int itemViewID) {
        super(mContext, mDatas, itemViewID);
    }


    public void setOnItemButtonClickListener(OnItemButtonClickListener onItemButtonClickListener) {
        this.onItemButtonClickListener = onItemButtonClickListener;
    }

    @Override
    void bindData(BaseViewHolder holder, final int position) {
        Ware ware = (Ware) mDatas.get(position);
        Picasso.with(mContext).load(ware.getImgUrl()).into(holder.getImageView(R.id.id_hot_img));
        holder.getTextView(R.id.id_hot_content).setText(ware.getName());
        holder.getTextView(R.id.id_hot_price).setText("￥"+ware.getPrice());
        holder.getButton(R.id.id_hot_btn).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemButtonClickListener.OnClick(v, (Ware) mDatas.get(position));
            }
        });
    }

    public interface OnItemButtonClickListener {
        void OnClick(View view, Ware ware);
    }
}
